<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath%>">
<title>卡定义申请</title>
<%@ include file="/WEB-INF/jsp/common/common.jsp"%>
<script src="js/jquery.validate.js" type="text/javascript"></script>
<script src="js/jquery.divbox.js" type="text/javascript"></script>
<style type="text/css">
.input_text {
	width: 250px;
}

.select_1 {
	width: 250px;
}

input.fieldError {
	border: 1px solid #ffb042;
	background-color: #fffbf5;
}

textarea.fieldError {
	border: 1px solid #ffb042;
	background-color: #fffbf5;
}

label.fieldError {
	line-height: 23px;
	color: #ffb042;
	padding-left: 6px;
}
</style>
<script type="text/javascript">
// -------激活卡模板弹窗-------
//打开激活卡窗口
function openTempDiv(pageIndex,obj){
	$('#search_id').val('');
	$('#search_name').val('');
	$("#"+obj.id).blur();
	queryCarTemplate(pageIndex)
}
//调用拼接参数的方法，并执行查询
function queryCarTemplate(pageIndex){
	var id = $('#search_id').val();
	var name = $('#search_name').val();
  	queryAllProds({size:8,current:pageIndex,id: id, name: name});
}
function queryAllProds(param){
	$.openLoading();
	$.ajax({
		url : "actirationCardApply/querydefinebyregion",
    	type : 'POST',
    	async : true,
    	data:param,
    	dataType:'json',
    	success:function(page){
			$.closeLoading();
			if($.validate(page))return;
			var radioObj ="<input class='input_fxk' name='tempRadio' type='radio' value=''>";
			var fieldNames = "name,id";
			var tableContent = creatTable1(fieldNames,page,radioObj);
      		var tableObj = $("#templetTable");
      		tableObj.find("tbody").remove();
      		tableObj.append(tableContent);
			var strPage = creatChannelPage(page.current,6,page.maxPage,"72");
			var pageDIV = $("#templetpageDIV");
			pageDIV[0].innerHTML="";
			pageDIV.append(strPage);
			$("#addtempletDiv").OpenDiv();
			bindradio();
    }
  });
}
//点击“确定” ，选择 模板
function chooseTemp(){
  var selectedTemp= $(".table_highlighter");
  if(selectedTemp.length==0){
    $.message("error", "请选择一个激活卡定义");
    return;
  }
  var id = selectedTemp.children()[2].innerHTML;//模板代码
  var name = selectedTemp.children()[1].innerHTML;//模板代码
  $('#cardDefineId').val(id);
  $('#cardDefineName').val(name);
  closeCurrentDIV('addtempletDiv');
}
/* 查询条件重置 */
function tempReset() {
	$('#search_id').val('');
	$('#search_name').val('');
}
// -------激活卡模板弹窗-------
/* 选择高亮 */
function bindradio(){
	$("input[name='tempRadio']").click(function(){
		$("input[name='tempRadio']").parent().parent().removeClass("table_highlighter");
		$(this).parent().parent().addClass("table_highlighter");
   	});
}
//统一 关闭  窗口
function closeCurrentDIV(obj){
	$("#"+obj).CloseDiv();
}
// 申请重置 
/* function tempReset() {
	$('#cardDefineId').val('');
	$('#cardDefineName').val('');
	$('#unitPp').val('');
} */
/* 根据卡模板申请卡 */
function addApply() {
	var cardDefineId = $('#cardDefineId').val()
	var cardDefineName = $('#cardDefineName').val()
	var unitPp = $('#unitPp').val()
	var appMemo = $('#appMemo').val()
	if(!cardDefineName){
		$.message("error", "激活卡定义名称不能为空")
		return
	}else if(!cardDefineId){
		$.message("error", "激活卡定义代码不能为空")
		return
	}else if(!unitPp){
		$.message("error", "申请张数不能为空")
		return
	}
	addCardApply({cardDefineId: cardDefineId, cardDefineName: cardDefineName, unitPp: unitPp, appMemo: appMemo})
}
function addCardApply(param) {
	$.openLoading();
	$.ajax({
		url : "actirationCardApply/apply",
		type : 'POST',
		async : true,
		dataType:'json',
		data: param,
		success : function(data) {
			$.closeLoading();
			if("success"==data.result&&""!=data.message){
				$.message("success", data.message);
				self.location.href="<%=path%>/actirationCardApply/approval";
	    	}
			if("fail"==data.result){
	    		$.message("error", "系统错误,请联系管理员");
	    	}
			if("error"==data.result&&""!=data.message){
	    		$.message("error", data.message);
	    	}
		}
	})
}
</script>
<style type="text/css">
.ui-icon {
	display: block;
	text-indent: -99999px;
	overflow: hidden;
	background-repeat: no-repeat
}
</style>
</head>
<body>
	<div class="current">
		<table class="current_table_1">
			<tbody>
				<tr class="f2">
					<td><img src="./images/current_1.jpg"></td>
					<td class="current_table_1_td"><img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
						<span style="color: #136bab;">激活卡管理 <span
							style="padding: 0 5px; font-weight: bold; line-height: 28px;">&gt;</span>激活卡申请审核
							<span
							style="padding: 0 5px; font-weight: bold; line-height: 28px;">&gt;</span>申请
					</span></td>
					<td><img src="./images/current_3.jpg"></td>
				</tr>
			</tbody>
		</table>
	</div>

	<form id="inputForm">
		<table class="table_05">
			<tbody>
				<tr>
					<td colspan="4"
						style="font-size: 12px; font-weight: bold; text-align: left; color: #3876bf; line-height: 17px; background-image: url(images/centent_1.jpg)">申请激活卡</td>
				</tr>
				<tr>
					<th width="25%">卡定义名称：</th>
					<td width="28%"><input id="cardDefineName"
						name="cardDefineName" type="text" readonly="true"
						style="background-color: #ccc;" class="input_text"><span
						class="red">*</span><input
						type="button" class="input_button_2" id="searchBtn" value="选择卡定义"
						onClick="openTempDiv(1,this)" /></td>
					<th width="20%">卡定义代码：</th>
					<td width="22%"><input name="cardDefineId" id="cardDefineId"
						type="text" readonly="true" style="background-color: #ccc;"
						class="input_text"><span class="red">*</span> </td>
				</tr>


				<tr>
					<th>申请张数：</th>
					<td colspan="3"><input name="unitPp" id="unitPp" type="text" maxlength="5"
						class="input_text" onkeyup="value=value.replace(/[^\d]/g, '').replace(/^0{1,}/g,'')"><span class="red">*</span></td>
				</tr>
				<tr>
					<th>申请说明：</th>
					<td colspan="3"><textarea name="appMemo" id="appMemo"
							maxlength="250" rows="5" class="textarea_1"></textarea></td>
				</tr>
			</tbody>
		</table>
		<div align="center">
			<input id="sub" class="input_button_1" name="" type="button"
				value="确定" onclick="addApply()">&nbsp;&nbsp; <input
				class="input_button_1" name="" onclick="reset()" type="button"
				value="重置">
		</div>
	</form>
	<!--   	添加模板 DIV 默认隐藏-->
	<div id="addtempletDiv" style="display: none; width: 80%">
		<input type="hidden" id="row_num" name="row_num" value="0" />
		<div class="table_title_div">
			<table class="table_title" style='width: 100%;'>
				<tr>
					<td width="10%"></td>
					<td width="80%" id="interfaceName"></td>
					<td width="10%" align="right"><img
						src="<%=path%>/images/closedown.gif" alt="关闭"
						onclick="closeCurrentDIV('addtempletDiv')" /></td>
				</tr>

			</table>
		</div>
		<form id="inputForm" action="save.jhtml" method="post"
			enctype="multipart/form-data">

			<table class="table_02" id="addTempleteTable" style="height: 180px;"
				align="center">
				<tbody>
					<tr>
						<td>
							<table class="search_table">
								<tbody>
									<tr height="30px">
										<td width="40%" height="30">卡定义名称： <input name="txt3"
											id="search_name" type="text" class="input_text" value="">
										</td>
										<td width="40%" height="30">卡定义号： <input name="txt3"
											id="search_id" type="number" class="input_text" value="">
										</td>
										<td width="20%" height="30"><input type="button"
											class="input_button_1" id="searchBtn" value="查询"
											onclick="queryCarTemplate(1)">&nbsp; <input
											type="button" class="input_button_1" id="searchBtn"
											value="重置" onclick="tempReset()"></td>
									</tr>
								</tbody>
							</table>
						</td>
					</tr>
					<tr>
						<td>
							<table id="templetTable" class="content_table_1">
								<thead>
									<tr class="f1">
										<th style="width: 5%">选择</th>
										<th style="width: 65%">卡定义名称</th>
										<th style="width: 20%">卡定义号</th>
									</tr>
								</thead>
								<tbody>
								</tbody>
							</table>
							<div id="templetpageDIV" class="page"></div>
						</td>
					</tr>
				</tbody>
			</table>
			<div align="center">
				<input class="input_button_3" name="" type="button"
					onclick="chooseTemp()" value="确定">&nbsp;&nbsp; <input
					class="input_button_3" name="" type="button"
					onclick="closeCurrentDIV('addtempletDiv')" value="取消">
			</div>
		</form>
	</div>
</body>
</html>